package com.useeinfo.oa.open.admin.maintaining;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.sugar.data.QueryParam;
import com.useeinfo.oa.modules.base.entity.Enterprise;
import com.useeinfo.oa.modules.maintaining.biz.WorkingHoursBiz;
import com.useeinfo.oa.modules.maintaining.entity.WorkingHours;
import com.useeinfo.oa.modules.security.util.SessionKeyUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @Auther: xudong.sun
 * @Date: 2018/12/28 14:59
 * @Description:
 */
@Controller
@RequestMapping("/web/admin/workingHours")
public class WorkingHoursAdminAction {

    @Autowired
    private WorkingHoursBiz workingHoursBiz;

    @Autowired
    private HttpServletRequest httpServletRequest;

    /**
     * 打开列表页面
     */
    @RequestMapping("/list")
    public ModelAndView list() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("pages/admin/workingHours/list");
        return modelAndView;
    }


    /**
     * 查询列表
     *
     * @param pageNowParam
     * @param pageSizeParam
     * @param searchCode
     * @param orderBy
     * @return
     */
    @RequestMapping("/listJson")
    @ResponseBody
    public JSONObject listJson(@RequestParam(value = "pageNo", required = false) String pageNowParam,
                               @RequestParam(value = "pageSize", required = false) String pageSizeParam,
                               @RequestParam(value = "searchCode", required = false) String searchCode,
                               @RequestParam(value = "orderBy", required = false) String orderBy
    ) {
        Enterprise enterprise = SessionKeyUtils.getSessionEnterprise(httpServletRequest);
        QueryParam queryParam = new QueryParam(pageNowParam, pageSizeParam);
        queryParam.getSqlMap().put("searchCode", searchCode);
        if (enterprise != null) {
            queryParam.getSqlMap().put("enterpriseId", enterprise.getId() + "");
        }
        if (StringUtils.isNotBlank(orderBy)) {
            queryParam.setSqlOrder("order by " + orderBy);
        }
        return workingHoursBiz.findJSONList(queryParam);
    }

}
